package com.boot.mgt.controller.web

import com.boot.core.result.ResultTo
import com.boot.mgt.model.vo.EditReportVo
import com.boot.mgt.service.TaAccidentReportService
import com.boot.mgt.service.TaAccidentService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import javax.servlet.http.HttpServletRequest

/**
 * 报警管理接口
 */
@RestController
@RequestMapping("/admin/report")
class TaAccidentReportController {

    @Autowired
    private lateinit var accidentReportService: TaAccidentReportService

    @Autowired
    private lateinit var accidentService: TaAccidentService

    /**
     * 案件指派
     */
    @PostMapping("/designate")
    fun addReport(accident_report_id: Int, police_type: Int, police_number:String): ResultTo {
        return accidentService.designate(accident_report_id, police_type, police_number)
    }

    /**
     * 案件指派
     */
    @GetMapping("/doDesignate")
    fun doAddReport(accident_report_id: Int, police_type: Int, police_number:String): ResultTo {
        return accidentService.designate(accident_report_id, police_type, police_number)
    }

    /**
     * 获取案件转发记录
     */
    @GetMapping("/selectForwardLog")
    fun selectForwardLog(accident_report_id: Int): ResultTo {
        return accidentReportService.selectForwardLog(accident_report_id)
    }

    /**
     * 报警信息列表
     */
    @GetMapping("/list")
    fun list(request: HttpServletRequest,
             page_index: Int?, page_size: Int?): ResultTo {
        val map = hashMapOf<String, Any>()
        request.parameterMap?.apply {
            for (paramMap in this) {
                map[paramMap.key] = paramMap.value[0]
            }
        }
        map["isWeb"] = true
        return accidentReportService.list(page_index, page_size, map)
    }

    /**
     * 获取ID最大的数据
     */
    @GetMapping("/id/max")
    fun selectIdMax(): ResultTo {
        return accidentReportService.selectForIdMax()
    }

    /**
     * 报警信息详情
     */
    @GetMapping("/detail")
    fun detail(id: Int, asssign_id: Int?): ResultTo {
        return accidentReportService.detail(id, false)
    }

    /**
     * 编辑报警信息
     */
    @PostMapping("/edit")
    fun editReport(@RequestBody editReportVo: EditReportVo): ResultTo {
        return accidentReportService.edit(editReportVo)
    }

    /**
     * 案件结束（快赔）
     */
    @PostMapping("/cc_operation")
    fun ccOperation(accident_report_id: Int, cc_operation_type: String): ResultTo {
        return accidentReportService.ccOperation(accident_report_id, cc_operation_type)
    }

    /**
     * 案件结束（快赔）
     */
    @GetMapping("/doCc_operation")
    fun doCc_operation(accident_report_id: Int, cc_operation_type: String): ResultTo {
        return accidentReportService.ccOperation(accident_report_id, cc_operation_type)
    }
}